home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / units < prev    next >
Internet Message Format  |  1995-03-31  |  4KB

  1. From comp.sys.handhelds Mon Feb 11 13:38:18 1991
  2. Path: mentor.cc.purdue.edu!purdue!haven!decuac!shlump.nac.dec.com!jareth.enet.dec.com!edp
  3. From: edp@jareth.enet.dec.com (Eric Postpischil (Always mount a scratch monkey.))
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Units -- user-specified basis
  6. Message-ID: <20064@shlump.nac.dec.com>
  7. Date: 11 Feb 91 14:39:18 GMT
  8. Sender: newsdaemon@shlump.nac.dec.com
  9. Reply-To: edp@jareth.enet.dec.com (Eric Postpischil (Always mount a scratch monkey.))
  10. Organization: Digital Equipment Corporation
  11. Lines: 63
  12.  
  13. Here's a program that implements the function of UBASE for any set of desired
  14. base units.  This can be used to convert a unit expression to base cgs or
  15. English units, or for weirder purposes. 
  16.  
  17. To use, create a list of eight units.  Each item in the list can be just the
  18. name of a unit, e.g. { cm g s . . . }, or items can be more complicated unit
  19. expressions, such as 1_m*s.  The units of the eight items must be linearly
  20. independent -- there must not be any way to multiply and divide any selection
  21. of up to seven items so that they equal an eighth.  This is equivalent to
  22. saying there must be a way to convert each HP-48 base unit, including "mol" and
  23. "?", to one of the units in the list you supply.
  24.  
  25. Put that list in stack level one and execute SETU (Set Units).  It will create
  26. a variable Upar which is that list plus a new element -- an 8-by-8 array.
  27.  
  28. To convert a unit expression to your basis, put the unit expression in level 1
  29. and execute CONVERTB (Convert to Basis).
  30.  
  31. Some notes:
  32.  
  33. Units will appear in the resulting expression in the order they appear in your
  34. list (except that if the list contains compound unit expressions, elements of
  35. them may be combined -- e.g., if you have m*s and m*g, you may get m^2*... in
  36. the result).
  37.  
  38. Be careful when converting temperatures.
  39.  
  40. Fractional exponents are not supported.  Fractional exponents in your input
  41. will be rounded to integers.  You might be able to get away with some
  42. fractional outputs by removing the 0 RND in CONVERTB -- but be aware that the
  43. array calculations may give results like .999999..., and removing the 0 RND
  44. will leave these in the output.  If you expect 1/2 powers in your output, then
  45. 1 RND would be good, and 9 RND or something might be suitable in other cases.
  46.  
  47. If you will not be using "mol" or "?", the program could be altered to work
  48. on fewer than all 8 base units, with some savings in space and possibly time.
  49.  
  50. You can recall Upar, edit it, and pass it to SETU to change the base units.
  51. SETU will ignore the ninth element, the array.
  52.  
  53.  
  54.                 -- edp (Eric Postpischil)
  55.                 "Always mount a scratch monkey."
  56.                 edp@jareth.enet.dec.com
  57.  
  58.  
  59. My routines use Bill Wickes' DIMS, so here it is again.  Download it, convert
  60. it with ASC->, and store it in a variable called 'DIMS'.
  61.  
  62. %%HP: T(3)A(D)F(.);
  63. "D9D20D29512BF81B7040D9D2044EF0A211693045FC436ADB46AAC35F30403C37
  64. 088130E4A2070000FF40D35D53453392020000000000072102C230178A2CB916
  65. D9D20339202000000000006520189A2B21303223019D35433706B436AAC35442
  66. 30B2130B21303587"
  67.  
  68.  
  69. Here is the directory 'BASIS', checksum #65FA.  Interestingly, 'BASIS' BYTES
  70. gives 268.5 bytes, 'BASIS' RCL BYTES gives 269 bytes.
  71.  
  72. %%HP: T(3)A(R)F(.); DIR CONVERTB \<< DUP DIMS { 1 8 } \->ARRY Upar 9 GET * 0
  73. RND \-> e \<< 1 1 8 FOR i Upar i GET e i GET ^ _ NEXT CONVERT \>> \>> SETU \<<
  74. \-> list \<< 1 8 FOR i 1 list i GET _ DIMS NEXT { 8 8 } \->ARRY INV list 1 8
  75. SUB SWAP + 'Upar' STO \>> \>> END 
  76.  
  77.